----------------------------------------------------------------------
Replication code for "Leakage does not fully offset soy supply-chain efforts to reduce deforestation in Brazil"

Authors: Nelson Villoria, Rachael Garrett, Florian Gollnow, Kimberly
Carlson

Code written by Nelson B. Villoria (nvilloria@ku.edu)

This version: April 14, 2022.
----------------------------------------------------------------------

We use GEMPACK (https://www.copsmodels.com/gempack.htm) to solve the
GTAP-AEZ model. All the programs and files needed to replicate our
results are in the folders ./GTAP_PROGRAMS and ./GTAP_DATA. The user
is responsible for securing the necessary licenses for both GEMPACK
and the GTAP database (https://www.gtap.agecon.purdue.edu/). The R
scripts in the R_PROGRAMS folder processes model results to create the
results displayed in the text.

The resulting output are ~120 GEMPACK output files (har, upd, slc)
files that occupy ~120 MB. Execution of the code takes from 25 minutes
to few hours, depending on machine speed.


* The provided folder structure must be kept for the programs to run.


There are thirty databases in the folder GTAP_DATA covering:

* Five Spatial Footprint Scenarios (SFS): Amazon Soy Moratorium (SM),
  Global ZDC (ZD), Europe (EU), China (CN), Europe and China (EC).

* Three Market Coverage Scenarios (MCS).

* Two Fores Type Scenarios (FT).

Sequence of programs to build results:
--------------------------------------

* Start with the GTAP programs in the folder GTAP_PROGRAMS.

* The GTAP model used in all the simulations is documented in
  GTAPAEZ3_ENDETA.tab. The auto-executable GTAPAEZ3_ENDETA.exe was
  built using TABLO V 7.0 with Fortran Compiler GF 64 version 6.4.0 64
  bit. This model allows for endogenous determination of the ETA
  parameter. All the CMF files described below have swap statements
  through which ETA becomes exogenous, which is what we use for the
  final results (ETA = 0.66), as explained in the Methods section and
  in the supplementary materials.

* The file runbaseandexps.bat executes the program GTAPAEZ3_ENDETA.exe
  by calling two CMF files:

** allmacrs_ex_BA.cmf: Produces a baseline without ZDC FOR EACH ONE of
   the 30 GTAP databases (5 SFS 3 MCS X 2 FT) that contain the spatial
   foot print of the Amazon Soy Moratorium (see paper's methods for
   explanations of the spatial footprint scenarios (SFS), market
   coverage scenarios (MCS) and forest types.

** allmacrs_ex_ZD.cmf: Takes as an input the shocks and regions with
   ZD produced by allmacrs_ex_BA.cmf and fix the change in forest in
   the portion of Brazil subject to the ZDC, by swapping it with a
   producer subsidy:

swap tf(areg, "Forestry","Brazil") = p_LANDCOVER_L(areg,
"Forest","Brazil");

where areg is the set of AEZ-Biome splits under ZD regime "A" and
non-zero cropland. This set is written by the model in files named
*_out.har written by allmacrs_ex_BA.cmf.

** The result files have the following naming convention:
allmacrs_ex_BA_SMA2_2017_out.har: Baseline for the Amazon Moratorioum
(SM) using MCS 2 and FT "A".  allmacrs_ex_ZD_SMA2_2017_out.har:
Results of applying the ZDC in the AMS using MCS 2 and FT "A".

* Post-processing of results using R:

** Run the load.r function

** Then run do.r

** Both load.r and do.r rely on functions.r, which have custom
   functions for data processing as well as R packages.

